Skip to content

Proposed alternate prompting scheme#241

Draft
gvanrossum wants to merge 1 commit into
microsoft:mainfrom
gvanrossum:history
Draft

Proposed alternate prompting scheme#241
gvanrossum wants to merge 1 commit into
microsoft:mainfrom
gvanrossum:history

Conversation

@gvanrossum
Copy link
Copy Markdown
Collaborator

@gvanrossum gvanrossum commented Apr 22, 2024

This is my proposal to address #39. It also fixes the issue I flagged in #240 about the user input being repeated twice. I tried it with my demo from #238 and that seems to work.

The prompt structure is as follows:

  • System: "You are a ..., up to and including the schema, with instructions for how to format the JSON"
  • prompt_prelude (user and bot messages)
  • User: (the user request)

I don't understand how your test tools work (I'm a dinosaur, I don't know how hatch or toml or pipenv work, I can handle pytest though).

@DanielRosenwasser

@DanielRosenwasser
Copy link
Copy Markdown
Member

So this matches my intuition around how to put all of this together. While we have no way of testing for a regression, I'd be okay with running with something like this for now. The thing I'll note is that when @ahejlsberg tried something like this with the system prompt, he got slightly worse results.

That said, he guessed part of this was probably tied to the schema falling further and further behind in history. So maybe something to alleviate this would be to instead do:

  • prompt_prelude (user and bot messages)
  • System: "You are a ..., up to and including the schema, with instructions for how to format the JSON"
  • User: (the user request)

Basically, move the system prompt immediately before the user request.


I don't understand how your test tools work

No worries. To most quickly fix the build:

cd TypeChat/python
pip install -e .[dev,examples]
pytest --snapshot-update
git add tests
git commit -m "Update snapshots."

@DanielRosenwasser
Copy link
Copy Markdown
Member

It probably also makes sense to make the repair prompt a system message as well.

@DanielRosenwasser
Copy link
Copy Markdown
Member

One of the things I tried in https://github.com/microsoft/TypeChat/tree/systemPromptPython (ea0e0d8) was to take the approach here after fixing some issues. As @ahejlsberg mentioned, OpenAI unfortunately doesn't do a great job when you switch to the system prompts. Trying things out on the coffee shop example input file, it generally got more "wrong".

One idea we could try is to expose the (very basic) logic we use to parse out JSON so that people can override translate and do whatever they want.

But otherwise, the only other approaches I could advise to implement something like #238 is to experiment with preambles to talk about past state.

@gvanrossum
Copy link
Copy Markdown
Collaborator Author

Thanks for the feedback!

Preamble issues

My problem with the preamble is that it is prefixed to the prompt containing the schema, which makes the conversation a bit awkward, as it goes like this (ignoring system messages):

  • user: draw three squares
  • bot: {some JSON}
  • user: make them bigger
  • bot: {some JSON}
  • user: Please translate user requests into JSON using this schema: {schema JSON}. Here is a user question: make them red

What I want is this (because my intuition tells me that it's a more natural dialog):

  • user: Please translate user requests into JSON using this schema: {schema JSON}. Here is a user question: draw three squares
  • bot: {some JSON}
  • user: make them bigger
  • bot: {some JSON}
  • user: make them red

About system messages:

My (rudimentary) understanding of system messages is that it's meant to set a behavior or personality that's hard(er) to subvert by users trying to be clever -- e.g. the system prompt would tell the model not to be racist. In TypeChat's case, I think that at best the prompt that sets the schema should be a system prompt, but the repair prompts should probably just be user prompts.

The docs say a little bit about this. It makes me think that it's not worth experimenting too much with this in particular.

I also just noticed "JSON Mode" in the docs, which may or may not be useful for TypeChat.

@ahejlsberg
Copy link
Copy Markdown
Member

ahejlsberg commented May 2, 2024

@gvanrossum FWIW, a while back I did a multi-turn experiment where I didn't include previous replies in the prompt, but rather just repeated the request with the additional user input concatenated to the the previous user input (separated by newlines). So, your example would have a single user prompt section with text like:

Please translate user requests into JSON using this schema:
{schema JSON}.
Here is a user question:
draw three squares
make them bigger
make them red

It seemed to work quite well. Wonder if that would work in your case?

@ahejlsberg
Copy link
Copy Markdown
Member

ahejlsberg commented May 2, 2024

I also just noticed "JSON Mode" in the docs, which may or may not be useful for TypeChat.

The reason we aren't using JSON Mode is that there is no good way to know upfront if a model supports it, and, unfortunately, older models don't know to ignore it, but instead error on the request.

Also, not getting JSON back from requests hasn't really been an issue.

@gvanrossum
Copy link
Copy Markdown
Collaborator Author

gvanrossum commented May 2, 2024 via email

robgruen added a commit that referenced this pull request Jun 1, 2026
* Install python-dotenv and tabulate

* Small working demo that can draw boxes on a canvas

The idea is that you can write a small amount of JavaScript that reads the
JSON and renders in an HTML5 canvas, or some Python that renders it in Tkinter,
or anything else that strikes your fancy.

I would like to use this to draw diagrams representing the stack and
memory layout for an interpreter, to be used in internal docs.

* Add chat history to drawing demo

* [WIP] Hack on translation a bit

* New API for chat history

* Improved the schema with ChatGPT's help. Added Arrow and Ellipse.

* rendering program using Tkinter

* Add a simple rendering function (most of it written by ChatGPT)

* Added dashed and dotted arrows (some help from ChatGPT)

* Rip oput history, for now

* Make pyright happy

* Keep pydantic also happy

* Add (flawed) history based on prompt_preamble

* Prune history

* Add temporary logging

* Alternate prompting scheme from #241

* Revert changes to translator.py

* Use Anders' suggestion for history

(Just append the inputs, separated by newlines.)

* Switch schema to dataclasses

* Black formatting

* Remove unused imports

* Clarify Failure output

* Revert verbose logging

* Reuse drawing window

* Don't crash if we cannot import readline (e.g. on Windows)

* Add crude progress messages

* Address PR #238 review-thread feedback in drawing example and interactive input helper

Restrict Style.line_style to Literal["solid", "dashed", "dotted"], align the
UnknownText discriminant to Literal["Unknown"], fix the Arrow docstring, harden
the dash-pattern lookup with a safe fallback to solid, and mark the optional
readline import as intentionally unused (noqa: F401).

---------

Co-authored-by: robgruen <robgruen@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants